﻿using System;
using System.Windows.Data;
using System.Globalization;

namespace OverlakeApp.Converters
{
    /// <summary>
    /// Converts from a tick representation of a timespan to a string in the format of hours:minutes.
    /// </summary>
    public class TicksToTimespanStringConverter : IValueConverter
    {
        /// <summary>
        /// Convert from ticks to a string in the format hours:minutes.
        /// </summary>
        /// <param name="value">The timespan in ticks.</param>
        /// <param name="targetType">Not used.</param>
        /// <param name="parameter">Not used.</param>
        /// <param name="culture">Not used.</param>
        /// <returns>A string representing the timespan in hours:minutes format.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is long))
                return null;

            return TimeSpan.FromTicks((long)value).ToString(@"h\:mm");
        }

        /// <summary>
        /// Not implemented.
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
